package dc.singleNumber;

import java.util.ArrayList;
import java.util.List;

import utils.FileUtils;
import distribution.DistributionScheme;
import distribution.SchemeItem;

public class ScatterCodes {

	public static void method1() {
		StringBuffer sb = new StringBuffer();
		int max = 33;
		int count = 1;
		List<SchemeItem> allCombination = DistributionScheme.allCombination(33,
				6);
		List<SchemeItem> relsut = new ArrayList<SchemeItem>();
		int index = allCombination.size() - 1;

		long currentbit = 0;
		while (allCombination.size() > 0) {
			if (relsut.size() % 5 == 0 || index < 0) {
				System.out.println((count++));
				if (relsut.size() > 0) {
					sb
							.append("--------------------------------------------------------------------\r\n");
					for (SchemeItem si : relsut) {
						sb.append(si).append("\r\n");
					}
				}

				relsut.clear();

				SchemeItem si = allCombination.get(allCombination.size() - 1);
				currentbit = si.getBitCode();
				relsut.add(si);
				allCombination.remove(allCombination.size() - 1);
				index = allCombination.size() - 1;
				continue;
			}

			if ((currentbit & allCombination.get(index).getBitCode()) == 0) {
				currentbit |= allCombination.get(index).getBitCode();
				relsut.add(allCombination.get(index));
				allCombination.remove(index);
			}

			index--;

		}

		FileUtils.writeFile("c:\\001.txt", sb.toString(), "GBK");
	}

	public static void method2() {
		StringBuffer sb = new StringBuffer();
		int max = 33;
		int count = 1;
		List<SchemeItem> allCombination = DistributionScheme.allCombination(33,
				6);
		List<SchemeItem> relsut = new ArrayList<SchemeItem>();
		int index = allCombination.size() - 1;

		long currentbit = 0;
		while (allCombination.size() > 0) {
			if (relsut.size() % 5 == 0 || index < 0) {
				System.out.println((count++));
				if (relsut.size() > 0) {
					sb
							.append("--------------------------------------------------------------------\r\n");
					for (SchemeItem si : relsut) {
						sb.append(si).append("\r\n");
					}
				}

				relsut.clear();

				SchemeItem si = allCombination.get(allCombination.size() - 1);
				currentbit = si.getBitCode();
				relsut.add(si);
				allCombination.remove(allCombination.size() - 1);
				index = allCombination.size() - 1;
				continue;
			}

			if ((currentbit & allCombination.get(index).getBitCode()) == 0) {
				currentbit |= allCombination.get(index).getBitCode();
				relsut.add(allCombination.get(index));
				allCombination.remove(index);
			}

			index--;

		}

		FileUtils.writeFile("c:\\001.txt", sb.toString(), "GBK");
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		// Integer[] codes = new Integer[]{1,2,3,4,5,6};
		// SchemeItem si = new SchemeItem(codes);
		// System.out.println(si.getBitCode());
	}

	

}
